﻿namespace Library
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    public class winxpbutton : Button
    {
        private Color m_textcolor = Color.Black;
        private bool my_mouseDown = false;
        private bool my_mouseHover = false;
        private ToolTip toolTip = new ToolTip();
        private string toolTipText = "";

        public winxpbutton()
        {
            this.InitializeComponent();
            base.SetStyle(ControlStyles.UserPaint, true);
            base.MouseDown += new MouseEventHandler(this.my_OnMouseDown);
            base.MouseUp += new MouseEventHandler(this.my_OnMouseUp);
            base.MouseEnter += new EventHandler(this.my_OnMouseEnter);
            base.MouseLeave += new EventHandler(this.my_OnMouseLeave);
            this.toolTip.SetToolTip(this, "页导航");
            base.Height = 0x17;
            base.Width = 0x4b;
        }

        private void DrawBorder(Graphics g, int state)
        {
            Pen pen;
            if (state == 1)
            {
                pen = new Pen(SystemColors.ControlLightLight, 2f);
                g.DrawLine(pen, 1, 1, 1, base.Height - 2);
                g.DrawLine(pen, 1, 1, base.Width - 2, 1);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 2);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 2, base.Height - 1);
            }
            else if (state == 2)
            {
                pen = new Pen(Color.Yellow, 2f);
                g.DrawLine(pen, 1, 1, 1, base.Height - 2);
                g.DrawLine(pen, 1, 1, base.Width - 2, 1);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 2);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 2, base.Height - 1);
            }
            else if (state == 3)
            {
                pen = new Pen(SystemColors.ControlDark, 2f);
                g.DrawLine(pen, 1, 1, 1, base.Height - 2);
                g.DrawLine(pen, 1, 1, base.Width - 2, 1);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 2);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 2, base.Height - 1);
            }
            else if (state == 4)
            {
                pen = new Pen(SystemColors.ControlLight, 2f);
                g.DrawLine(pen, 1, 1, 1, base.Height - 2);
                g.DrawLine(pen, 1, 1, base.Width - 2, 1);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 2);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 2, base.Height - 1);
            }
            else if (state == 5)
            {
                pen = new Pen(Color.SkyBlue, 2f);
                g.DrawLine(pen, 1, 1, 1, base.Height - 2);
                g.DrawLine(pen, 1, 1, base.Width - 2, 1);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 2);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 2, base.Height - 1);
            }
            if (state == 4)
            {
                pen = new Pen(Color.FromArgb(0xa1, 0xa1, 0x92), 1f);
                g.DrawLine(pen, 0, 2, 0, base.Height - 3);
                g.DrawLine(pen, 2, 0, base.Width - 3, 0);
                g.DrawLine(pen, base.Width - 1, 2, base.Width - 1, base.Height - 3);
                g.DrawLine(pen, 2, base.Height - 1, base.Width - 3, base.Height - 1);
                g.DrawLine(pen, 0, 2, 2, 0);
                g.DrawLine(pen, 0, base.Height - 3, 2, base.Height - 1);
                g.DrawLine(pen, base.Width - 3, 0, base.Width - 1, 2);
                g.DrawLine(pen, (int) (base.Width - 3), (int) (base.Height - 1), (int) (base.Width - 1), (int) (base.Height - 3));
            }
            else
            {
                g.DrawLine(Pens.Black, 0, 2, 0, base.Height - 3);
                g.DrawLine(Pens.Black, 2, 0, base.Width - 3, 0);
                g.DrawLine(Pens.Black, base.Width - 1, 2, base.Width - 1, base.Height - 3);
                g.DrawLine(Pens.Black, 2, base.Height - 1, base.Width - 3, base.Height - 1);
                g.DrawLine(Pens.Black, 0, 2, 2, 0);
                g.DrawLine(Pens.Black, 0, base.Height - 3, 2, base.Height - 1);
                g.DrawLine(Pens.Black, base.Width - 3, 0, base.Width - 1, 2);
                g.DrawLine(Pens.Black, (int) (base.Width - 3), (int) (base.Height - 1), (int) (base.Width - 1), (int) (base.Height - 3));
            }
        }

        private void DrawContainFocusButton(Graphics g)
        {
            this.DrawBorder(g, 5);
            this.PaintBack(g, this.BackColor);
        }

        private void DrawDisableButton(Graphics g)
        {
            this.DrawBorder(g, 4);
            this.PaintBack(g, this.BackColor);
        }

        private void DrawMouseDownButton(Graphics g)
        {
            this.DrawBorder(g, 3);
            this.PaintBack(g, this.BackColor);
        }

        private void DrawMouseHoverButton(Graphics g)
        {
            this.DrawBorder(g, 2);
            this.PaintBack(g, this.BackColor);
        }

        private void DrawNormalButton(Graphics g)
        {
            this.DrawBorder(g, 1);
            this.PaintBack(g, this.BackColor);
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            base.Name = "";
        }

        private void my_OnMouseDown(object sender, MouseEventArgs e)
        {
            this.my_mouseDown = true;
        }

        private void my_OnMouseEnter(object sender, EventArgs e)
        {
            this.my_mouseHover = true;
            PaintEventArgs args = new PaintEventArgs(base.CreateGraphics(), base.ClientRectangle);
            this.OnPaint(args);
        }

        private void my_OnMouseLeave(object sender, EventArgs e)
        {
            this.my_mouseHover = false;
            PaintEventArgs args = new PaintEventArgs(base.CreateGraphics(), base.ClientRectangle);
            this.OnPaint(args);
        }

        private void my_OnMouseUp(object sender, MouseEventArgs e)
        {
            this.my_mouseDown = false;
            PaintEventArgs args = new PaintEventArgs(base.CreateGraphics(), base.ClientRectangle);
            this.OnPaint(args);
        }

        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            Pen pen = new Pen(this.BackColor, 3f);
            pevent.Graphics.DrawRectangle(pen, 0, 0, base.Width, base.Height);
            if (!base.Enabled)
            {
                this.DrawDisableButton(pevent.Graphics);
            }
            else if (this.my_mouseDown)
            {
                this.DrawMouseDownButton(pevent.Graphics);
            }
            else if (this.my_mouseHover)
            {
                this.DrawMouseHoverButton(pevent.Graphics);
            }
            else if (this.Focused)
            {
                this.DrawContainFocusButton(pevent.Graphics);
            }
            else
            {
                this.DrawNormalButton(pevent.Graphics);
            }
            pen.Dispose();
        }

        private void PaintBack(Graphics g, Color c)
        {
            g.DrawRectangle(new Pen(c), 2, 2, base.Width, base.Height);
        }

        private void WriteText(Graphics g)
        {
            int num = 0;
            int num2 = 0;
            Size size = g.MeasureString(this.Text, this.Font).ToSize();
            num = (base.Width - size.Width) / 2;
            num2 = (base.Height - size.Height) / 2;
            if (base.Enabled)
            {
                SolidBrush brush = new SolidBrush(this.m_textcolor);
                g.DrawString(this.Text, this.Font, brush, (float) num, (float) num2);
            }
            else
            {
                g.DrawString(this.Text, this.Font, Brushes.Gray, (float) num, (float) num2);
            }
        }

        [Description("Red")]
        public Color textcolor
        {
            get
            {
                return this.m_textcolor;
            }
            set
            {
                this.m_textcolor = value;
                base.Invalidate();
            }
        }

        [Description("提示信息")]
        public string ToolTipText
        {
            get
            {
                return this.toolTipText;
            }
            set
            {
                this.toolTipText = value;
                this.toolTip.AutoPopDelay = 0x1388;
                this.toolTip.InitialDelay = 0x3e8;
                this.toolTip.ReshowDelay = 500;
                this.toolTip.ToolTipTitle = value;
                this.toolTip.ShowAlways = true;
            }
        }
    }
}

